/**
 * 
 */
package br.unesp.ibb.lbbc.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @author esther
 *
 */
public class FileEC {

	
	public static void saveFile(double[][] matrix, String nomeSemExtensao){
		FileOutputStream fos = null;
		//if the FBA directory do not exist, create it.
		
		String userDir = System.getProperty("user.home");
		
		File folderFBA = new File(userDir+"\\FBA");
		
		if (!folderFBA.exists()){
			new File(userDir+"\\FBA").mkdir();
		}
		
		String local = userDir+"\\FBA\\"+nomeSemExtensao+".txt";
		java.io.File file = new java.io.File(local);
		try {
			fos = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		OutputStreamWriter out = new OutputStreamWriter(fos); 
		
		for (int i = 0; i < matrix.length; i++) {
			String line = "";
			for (int j = 0; j < matrix[0].length; j++) {
				line = line.concat(matrix[i][j]+"\t");
			}
			try {
				out.write(line+"\n");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		try {
			out.close();
			fos.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
